package NB;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import track2.context.Config;

public class IdnbFeature implements Serializable {

	private static final long serialVersionUID = 3446517622835004107L;

	public static final double NOVALUE = -1;

	// store the probability of each feature;
	public double click;

	// titleid_tokensid.txt
	public double[] titleClick;
	public double[] titleNotClick;

	// queryid_tokensid.txt
	public double[] queryClick;
	public double[] queryNotClick;

	// descriptionid_tokensid.txt
	public double[] descriptionClick;
	public double[] descriptionNotClick;

	// purchasedkeywordid_tokensid.txt
	public double[] purchaseClick;
	public double[] purchaseNotClick;

	public double[] adClick;
	public double[] adNotClick;

	public double[] advertiserClick;
	public double[] advertiserNotClick;

	public double[] userClick;
	public double[] userNotClick;

	public double[] depthClick;
	public double[] depthNotClick;

	public double[] positionClick;
	public double[] positionNotClick;

	public double[] titleImpression;
	public double[] queryImpression;
	public double[] descriptionImpression;
	public double[] purchaseImpression;
	public double[] adImpression;
	public double[] userImpression;
	public double[] advertiserImpression;

	public IdnbFeature() {

		titleClick = new double[Config.titleIdSize];
		titleNotClick = new double[Config.titleIdSize];
		// titleImpression = new double[Config.titleIdSize];

		queryClick = new double[Config.queryIdSize];
		queryNotClick = new double[Config.queryIdSize];
		// queryImpression = new double[Config.queryIdSize];

		descriptionClick = new double[Config.descriptionIdSize];
		descriptionNotClick = new double[Config.descriptionIdSize];
		// descriptionImpression = new double[Config.descriptionIdSize];

		purchaseClick = new double[Config.purchaseIdSize];
		purchaseNotClick = new double[Config.purchaseIdSize];
		// purchaseImpression = new double[Config.purchaseIdSize];

		adClick = new double[Config.adIdSize];
		adNotClick = new double[Config.adIdSize];
		// adImpression = new double[Config.adIdSize];

		advertiserClick = new double[Config.advertiserIdSize];
		advertiserNotClick = new double[Config.advertiserIdSize];
		// advertiserImpression = new double[Config.advertiserIdSize];

		userNotClick = new double[Config.userIdSize];
		userClick = new double[Config.userIdSize];
		// userImpression = new double[Config.userIdSize];

		depthNotClick = new double[4];
		depthClick = new double[4];

		positionNotClick = new double[4];
		positionClick = new double[4];

		click = 0.0;
		// initialize
		for (int i = 0; i < Config.queryIdSize; i++) {
			queryClick[i] = NOVALUE;
			queryNotClick[i] = NOVALUE;
			//queryImpression[i] = 0.0;
		}
		for (int i = 0; i < Config.titleIdSize; i++) {
			titleClick[i] = NOVALUE;
			titleNotClick[i] = NOVALUE;
			//titleImpression[i] = 0.0;
		}
		for (int i = 0; i < Config.descriptionIdSize; i++) {
			descriptionClick[i] = NOVALUE;
			descriptionNotClick[i] = NOVALUE;
			//descriptionImpression[i] = 0.0;
		}
		for (int i = 0; i < Config.purchaseIdSize; i++) {
			purchaseClick[i] = NOVALUE;
			purchaseNotClick[i] = NOVALUE;
		//	purchaseImpression[i] = 0.0;
		}
		for (int i = 0; i < Config.adIdSize; i++) {
			adClick[i] = NOVALUE;
			adNotClick[i] = NOVALUE;
			//adImpression[i] = 0.0;
		}
		for (int i = 0; i < Config.advertiserIdSize; i++) {
			advertiserClick[i] = NOVALUE;
			advertiserNotClick[i] = NOVALUE;
			//advertiserImpression[i] = 0.0;
		}
		for (int i = 0; i < Config.userIdSize; i++) {
			userClick[i] = NOVALUE;
			userNotClick[i] = NOVALUE;
			//userImpression[i] = 0;
		}
		for (int i = 0; i < 4; i++) {
			depthClick[i] = NOVALUE;
			depthNotClick[i] = NOVALUE;
			positionClick[i] = NOVALUE;
			positionNotClick[i] = NOVALUE;
		}

	}

	public static void putObject(IdnbFeature feature) {
		try {
			File file = new File(Config.idNaiveBayesFeaturePath);
			FileOutputStream fs = new FileOutputStream(file);
			ObjectOutputStream os = new ObjectOutputStream(fs);
			os.writeObject(feature);
			os.flush();
			os.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static IdnbFeature getObject() {
		IdnbFeature feature = null;
		try {
			File file = new File(Config.idNaiveBayesFeaturePath);
			FileInputStream fs = new FileInputStream(file);
			ObjectInputStream os = new ObjectInputStream(fs);
			feature = (IdnbFeature) os.readObject();
			os.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return feature;

	}
}
